package com.bvgol.examples.netty.heartbeat;/**
 * @Classname MyServerIdleHandler
 * @Description TODO
 * @Date 2021/7/15 10:07
 * @Created by GUOCHEN
 */

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/07/15 10:07
 */
public class MyServerIdleHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

        if (evt instanceof IdleStateEvent){
            IdleStateEvent idleStateEvent = (IdleStateEvent) evt;
            switch (idleStateEvent.state()){
                case ALL_IDLE:
                    System.out.println("读写空闲"+ctx.channel().remoteAddress());
                    break;
                case READER_IDLE:
                    System.out.println("读空闲"+ctx.channel().remoteAddress());
                    break;
                case WRITER_IDLE:
                    System.out.println("写空闲"+ctx.channel().remoteAddress());
                    break;
            }
        }
    }
}
